package com.lhx.arrray;

public class array_find_zhongjianyuansu {
    public static int pivotIndex(int[] arr) {
        int i=0;
        int j=arr.length-1;
        int sum_left = arr[0];
        int sum_right = arr[arr.length-1];
        while(i<j) {
            if(sum_left<sum_right) {
                i++;
                sum_left = sum_left + arr[i];
            } else if (sum_left>sum_right) {
                j--;
                sum_right = sum_right+arr[j];
            } else {
                i++;
                j--;
            }

        }
        return i;
    }

    public static void main(String[] args) {
        int[] arr = {1,7,3,6,5,6};
        int a = pivotIndex(arr);
        System.out.println(a);
    }
}
